import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'
import systemArray from './module/systemIndex'
import sysNameObj from '../sysNameObj'
import routesArray from './module' // 综合
// import mRoutesArray from './module/mIndex' // 开发
// import gateArr from './module/gateWay' // 网关
// import tmArray from './module/tmIndex' // 分析
// import bugArray from './module/bugIndex' // 诊断
// import pushArr from './module/mobilePush' // 推送
import wRoutesArray from './module/iapadmin/workSpaceList'

Vue.use(Router)

let router = new Router({
  mode: 'history',
  base: 'view',
  routes: [
    /* ******************************* 综合的登陆页面和 home 页面 ************************************* */
    {
      path: '/',
      component: () => import('../view/comm/login')
    },
    {
      path: '/home',
      component: () => {
        if (sysNameObj.systemSwitch === 'ON') {
          return import('../view/comm/self/home')
        } else {
          return import('../view/comm/other/home')
        }
      },
      children: routesArray
    },
    {
      path: '/work',
      component: () => import('../view/iapadmin/workIndex'),
      children: wRoutesArray
    },
    // {
      // path: '/iap/workspace',
      // component: () => import('../view/iapadmin/workspace/workspace')
    // },，
    // 旧的综合版home页面
    // {
    //   path: '/old_home',
    //   component: () => import('../view/comm/home'),
    //   children: routesArray
    // },
    /* ******************************* 开发的登陆页面和 home 页面 ************************************* */
    // {
    //   path: '/',
    //   component: () =>
    //     import('../view/iapadmin/login/login')
    // },
    // {
    //   path: '/home',
    //   component: () => import('../view/iapadmin/iapIndex'),
    //   children: mRoutesArray
    // },
    // {
    //   path: '/iap/workspace',
    //   component: () => import('../view/iapadmin/workspace/workspace_iap')
    // },
    /* ****************************** 网关的登陆页面和 home 页面 ************************************** */
    // {
    //   path: '/',
    //   component: () => import('../view/gateWay/gateLogin')
    // },
    // {
    //   path: '/home',
    //   component: () => import('../view/gateWay/gateHome'),
    //   children: gateArr
    // },
    /* ******************************* 分析的登陆页面和 home 页面 ************************************** */
    // {
    //   path: '/',
    //   component: () => import('../view/tmPaas/login/login')
    // },
    // {
    //   path: '/home',
    //   component: () => import('../view/tmPaas/tmHome/tmHome'),
    //   children: tmArray
    // },
    /* ****************************** 诊断的登陆页面和 home 页面 ************************************* */
    // {
    //   path: '/',
    //   component: () => import('../view/bugtags/login')
    // },
    // {
    //   path: '/home',
    //   component: () => import('../view/bugTags/bugHome'),
    //   children: bugArray
    // },
    /* ****************************** 推送的登陆页面和 home 页面 ************************************** */
    // {
    //   path: '/',
    //   component: () => import('../view/mobilePush/login')
    // },
    // {
    //   path: '/home',
    //   component: () => import('../view/mobilePush/pushHome'),
    //   children: pushArr
    // },
    /* ******************************************************************************************** */
    // 系统列表
    {
      path: '/systemList',
      component: () => {
        if (sysNameObj.systemSwitch === 'ON') {
          return import('../view/comm/self/systemList')
        } else {
          return import('../view/comm/other/systemList')
        }
      }
    },
    // 系统管理的home页面
    {
      path: '/systemHome',
      component: () => import('../view/systemManager/systemHome/systemHome'),
      children: systemArray
    },
    {
      path: '/pushIndex',
      component: () => import('../view/mobilePush/pushIndex')
    },
    // 测试页面
    {
      path: '/test',
      // path: '/home',
      component: () => import('../view/comm/test/test')
      // children: routesArray
    },
    {
      path: '/test1',
      component: () => import('../view/comm/test/test1')
    },
    {
      path: '/test2',
      component: () => import('../view/comm/test/test2')
    },
    {
      path: '/test3',
      component: () => import('../view/comm/test/test3')
    },
    {
      path: '/test4',
      component: () => import('../view/comm/test/test4')
    }
  ],
  scrollBehavior () {
    return { x: 0, y: 0 }
  }
})

router.afterEach((to, from, next) => {
  if (to.path === '/') {
    let attrList = Object.getOwnPropertyNames(window.sessionStorage)
    for (let val of attrList) {
      window.sessionStorage.removeItem(val)
    }
  } else if (to.path === '/systemList') {
    store.commit('pd_updateSystemList', [])
  }

  store.commit('pb_updateTitle', to.meta.title)
  store.commit('pd_updatePath', to.path)
})

export default router
